package com.config;

import org.luaj.vm2.ast.Str;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class Config {

    public static String readFileContent(String fileName) {
        File file = new File(fileName);
        BufferedReader reader = null;
        StringBuffer sbf = new StringBuffer();
        try {
            reader = new BufferedReader(new FileReader(file));
            String tempStr;
            while ((tempStr = reader.readLine()) != null) {
                sbf.append(tempStr);
            }
            reader.close();
            return sbf.toString();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return sbf.toString();
    }

    Queue<String> command;
    String content;

    public static String LuaPath;
    public Config(String path){


        command = new LinkedList<>();
        this.content = readFileContent(path);

        String[] arr = this.content.split(";");

        for (String cmd : arr){
            cmd = cmd.trim();
            if (cmd .equals("") )
                return;

            String[] cmds = cmd.split(" ");
            if (cmds.length <2){
                return;
            }
            String key = cmds[0];
            if (key.equals("set") ){
                if (cmds[1] .equals("lua_path") ){
                    LuaPath = cmds[2];

                }
            }
        }

    }
}
